from rest_framework.views import APIView
from rest_framework.generics import ListAPIView
from rest_framework.viewsets import ModelViewSet
from rest_framework.permissions import IsAdminUser

from meiduo_admin.serializers.categories import CategorySimpleSerializer
from meiduo_admin.serializers.serializers import ChannelsSerializer, ChannelTypeSerializer
from goods.models import GoodsChannel, GoodsCategory, GoodsChannelGroup



# GET /meiduo_admin/goods/channels/?page=<页码>&page_size=<页容量>
class ChannelsViewSet(ModelViewSet):
    """频道管理视图集"""
    serializer_class = ChannelsSerializer

    queryset = GoodsChannel.objects.all()

    permission_classes = [IsAdminUser]


# GET  `/meiduo_admin/goods/categories/`
class ChannelCategoriesView(ListAPIView):
    """频道对应一级分类视图"""
    permission_classes = [IsAdminUser]
    # 指定视图所使用的查询集
    queryset = GoodsCategory.objects.filter(parent=None)

    # 指定序列化器类
    serializer_class = CategorySimpleSerializer

    # 关闭分页
    pagination_class = None


# GET /meiduo_admin/goods/channel_types/
class ChannelTypesView(ListAPIView):
    """频道组视图"""
    permission_classes = [IsAdminUser]

    serializer_class = ChannelTypeSerializer

    queryset = GoodsChannelGroup.objects.all()

    pagination_class = None
    print(queryset)

